var actionPath='/system/module/';
var rootActionPath=parent.CONTEXT_PATH+actionPath;
jQuery(function($){

	$("#tg").treegrid({
		rownumbers: true,
		fitColumns: true,
		toolbar:'#toolbar',
		method: 'post',
		idField: 'id',
		url : rootActionPath+'queryAll.xhtml',
		treeField: 'text',
		fit:true
	});
});	
	
var editingId;
function add() {
	parent.$.modalDialog({
		title : I18N.addTitle,
		width : 400,
		height : 180,
		href : rootActionPath+'module_add.xhtml',
		buttons : [ {
			text : GLOBAL_I18N.global_button_confirm,
			handler : function() {
				parent.$.modalDialog.openner_treeGrid = $('#tg');
				var f = parent.$.modalDialog.handler.find('#form');
				f.submit();
			}
		},
		
		{
			text : GLOBAL_I18N.global_button_cancel,
			handler : function() {
				parent.$.modalDialog.handler.dialog('close');
			}
		} 
		
		]
	});
}

	
	
	
function del(){
	var row = $('#tg').treegrid('getSelected');
	if(!row){
		parent.showWarningBox(Audaque.format(GLOBAL_I18N.global_message_please_select_remove,I18N.moduleName)); 
		return;
	}
	parent.showConfirmBox(Audaque.format(GLOBAL_I18N.global_message_remove_ask,I18N.moduleName), function(bool) {
		if (bool) {	
			parent.postReturnJson
			(
				actionPath+'remove.xhtml',
				{id : row.id},
				function(result){
					if(result.success){
						$('#tg').treegrid('reload');
						parent.westLayout.panel('open').panel('refresh');//刷新左侧模块菜单
					}
				}
			);
		}
	});
}

function edit(){
	
	var row = $('#tg').treegrid('getSelected');
	if (!row){
		parent.showWarningBox(Audaque.format(GLOBAL_I18N.global_message_please_select_edit,I18N.moduleName));
		return;
	}
	
	parent.$.modalDialog({
		title : I18N.updateTitle,
		width : 400,
		height :180,
		href : rootActionPath+'goUpdate.xhtml?id='+row.id,
		buttons : [ {
			text : GLOBAL_I18N.global_button_confirm,
			handler : function() {
				parent.$.modalDialog.openner_treeGrid = $('#tg');
				var f = parent.$.modalDialog.handler.find('#form');
				f.submit();
			}
		},
		
		{
			text : GLOBAL_I18N.global_button_cancel,
			handler : function() {
				parent.$.modalDialog.handler.dialog('close');
			}
		} 
		
		]
	});
}